package com.ihr360.sharedservice.calendar.controller;

import com.ihr360.sharedservice.calendar.dto.StatutoryVacation;
import com.ihr360.sharedservice.calendar.service.StatutoryVacationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping(value = "/statutoryvacations/")
public class StatutoryVacationController {
    @Autowired
    private StatutoryVacationService statutoryVacationService;

    @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    List<StatutoryVacation> selectAll() {
        return statutoryVacationService.selectAll();
    }


    @GetMapping(value = "workingCalendar", produces = MediaType.APPLICATION_JSON_VALUE)
    List<StatutoryVacation> getWorkCalendarOfMonth(@RequestParam Integer year, @RequestParam Integer month) {
        return statutoryVacationService.getWorkingCalendar(year, month);
    }


    @GetMapping(value = "statutoryHoliday", produces = MediaType.APPLICATION_JSON_VALUE)
    List<StatutoryVacation> selectAllStatutoryHoliday(@RequestParam Integer year, @RequestParam Integer month) {
        return statutoryVacationService.selectAllStatutoryHoliday(year, month);
    }

    @GetMapping(value = "workdayForStatutoryHoliday", produces = MediaType.APPLICATION_JSON_VALUE)
    List<StatutoryVacation> selectAllWorkDayForStatutoryHoliday(@RequestParam Integer year, @RequestParam Integer month) {
        return statutoryVacationService.selectAllStatutoryHoliday(year, month);
    }

    @GetMapping(value = "permanentCalendar", produces = MediaType.APPLICATION_JSON_VALUE)
    List<Boolean> findPermanentCalendar(@RequestParam Date date) {
        return statutoryVacationService.findPermanentCalendar(date);
    }

    @GetMapping(value = "statutoryVacationBetweenMonth", produces = MediaType.APPLICATION_JSON_VALUE)
    List<String> getStatutoryVacationBetweenMonth(@RequestParam Date startMonth, @RequestParam Date endMonth) {
        return statutoryVacationService.getStatutoryVacationBetweenMonth(startMonth, endMonth);
    }


    @GetMapping(value = "statutoryHolidayVacationBetweenDay", produces = MediaType.APPLICATION_JSON_VALUE)
    List<StatutoryVacation> getStatutoryHolidayVacationBetweenDay(@RequestParam
                                                                  @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
                                                                  Date startDate,
                                                                  @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
                                                                  @RequestParam Date endDate) {
        return statutoryVacationService.getStatutoryHolidayVacationBetweenDay(startDate, endDate);
    }
}